// 导入页面组件
import { createRouter, createWebHashHistory } from 'vue-router'
const Home = () => import('./pages/home/Home.vue')
const WordList = () => import('./pages/word/WordList.vue')
const WordDetail = () => import('./pages/word/WordDetail.vue')
const AddWord = () => import('./pages/word/AddWord.vue')
const EditWord = () => import('./pages/word/EditWord.vue')
const WordSet = () => import('./pages/wordset/WordSet.vue')
const StudyPlan = () => import('./pages/studyplan/StudyPlan.vue')
const VoiceSetting = () => import('./pages/voicesetting/VoiceSetting.vue')
const Login = () => import('./pages/login/Login.vue')
const Register = () => import('./pages/register/Register.vue')
const WordLearning = () => import('./pages/wordlearning/WordLearning.vue')
const Test = () => import('./pages/test/Test.vue')
const TestData = () => import('./pages/test/TestData.vue')

// 路由配置
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页',
      requiresAuth: false
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      title: '登录',
      requiresAuth: false
    }
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,
    meta: {
      title: '注册',
      requiresAuth: false
    }
  },
  {
    path: '/words',
    name: 'WordList',
    component: WordList,
    meta: {
      title: '单词列表',
      requiresAuth: false
    }
  },
  {
    path: '/words/detail/:id',
    name: 'WordDetail',
    component: WordDetail,
    meta: {
      title: '单词详情',
      requiresAuth: false
    }
  },
  {
    path: '/words/add',
    name: 'AddWord',
    component: AddWord,
    meta: {
      title: '添加单词',
      requiresAuth: false
    }
  },
  {
    path: '/words/edit/:id',
    name: 'EditWord',
    component: EditWord,
    meta: {
      title: '编辑单词',
      requiresAuth: false
    }
  },
  {
    path: '/wordset',
    name: 'WordSet',
    component: WordSet,
    meta: {
      title: '单词集',
      requiresAuth: false
    }
  },
  {
    path: '/studyplan',
    name: 'StudyPlan',
    component: StudyPlan,
    meta: {
      title: '学习计划',
      requiresAuth: false
    }
  },
  {
    path: '/voicesetting',
    name: 'VoiceSetting',
    component: VoiceSetting,
    meta: {
      title: '语音设置',
      requiresAuth: false
    }
  },
  {
    path: '/wordlearning',
    name: 'WordLearning',
    component: WordLearning,
    meta: {
      title: '单词学习',
      requiresAuth: false
    }
  },
  {
    path: '/test',
    name: 'Test',
    component: Test,
    meta: {
      title: '测试页面',
      requiresAuth: false
    }
  },
  {
    path: '/test-data',
    name: 'TestData',
    component: TestData,
    meta: {
      title: '数据测试页面',
      requiresAuth: false
    }
  },
  // 404页面
  {
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

// 路由拦截器
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || '我爱背单词'
  
  // 简化的路由拦截器，暂时跳过登录检查以便测试
  next()
})

export default router